package request

import (
  "livefind/model/cases/query"
  servCommon "livefind/service/common"
  "time"

  "github.com/gin-gonic/gin"
  "go.mongodb.org/mongo-driver/bson/primitive"
)

// swagger:parameters CaseCreateReq
type CaseCreateReq struct {
  CaseNo      string   `json:"caseNo"`       // 案件编号
  CaseName    string   `json:"caseName"`     // 案件名
  CaseType    string   `json:"caseType"`     // 案件类型
  Inquisitor  []string `json:"inquisitor"`   // 调查员
  Description string   `json:"description" ` // 案件描述
  Creator     string   `json:"creator"`      // 创建人
}

// swagger:parameters CaseListReq
type CaseListReq struct {
  // 创建人
  // example:"测试员1"
  Creator string `json:"creator" form:"creator"`
  // 页码
  // example:1
  Page int `json:"page" form:"page"`
  // 页面数据条数
  // example:10
  PageSize int `json:"paseSize" form:"pageSize"`
  // 排序字段
  // example:"createTime"
  SortField string `json:"sortField" form:"sortField"`
  // 排序规则
  // example:-1,1
  SortRule int `json:"sortingRules" form:"sortRule"`
}

// swagger:parameters CaseGetReq
type CaseGetReq struct {
  // mongo ObjectID
  // required:true
  // example:"6123838275877d0f16e654f0"
  ID string `form:"id"`
}

func (req *CaseCreateReq) ConvertCreate2Query(c *gin.Context) *query.CaseQuery {
  // 之后从jwt中获取
  creator := "测试员1"
  //if creator == "" {
  //  claims := c.MustGet("claims").(sysReq.CustomClaims)
  //  creator = claims.NickName
  //}
  return &query.CaseQuery{
    CaseNo:      req.CaseNo,
    CaseName:    req.CaseName,
    CreateTime:  time.Now().Unix(),
    Creator:     creator,
    Description: req.Description,
    CaseType:    req.CaseType,
    Inquisitor:  req.Inquisitor,
  }
}

func (req *CaseListReq) ConvertList2Query(defaultSortField string) *query.CaseQuery {
  q := servCommon.ParseQueryRule(req)
  return &query.CaseQuery{
    Creator: req.Creator,
    Query: q,
  }
}

func (req *CaseGetReq) ConvertGetById2Query() (id primitive.ObjectID, err error) {
  id, err = primitive.ObjectIDFromHex(req.ID)
  return id, err
}
